<?php

declare(strict_types=1);

namespace App\Api\Controller;

use App\Api\Middleware\ApiLockMiddleware;
use App\Api\Middleware\CheckAuthMiddleware;
use App\Api\Middleware\ResponseMiddleware;
use App\Api\Request\StaffRequest;
use App\Api\Service\StaffService;
use App\Model\Order;
use App\Model\Staff;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;

#[Controller(prefix: 'api'), Middlewares([ResponseMiddleware::class])]
class StaffController
{
    /**
     * 登录
     * @param StaffRequest $request
     * @param StaffService $service
     * @return array
     */
    #[PostMapping('staff/login'), Middlewares([ApiLockMiddleware::class])]
    public function login(StaffRequest $request, StaffService $service): array
    {
        return $service->login($request->validated());
    }

    /**
     * 获取员工信息
     * @param StaffService $service
     * @return Staff
     */
    #[GetMapping('staff/personal'), Middlewares([CheckAuthMiddleware::class])]
    public function personal(StaffService $service): Staff
    {
        return $service->personal();
    }

    /**
     * 更新员工信息
     * @param StaffRequest $request
     * @param StaffService $service
     * @return void
     */
    #[PutMapping('staff/personal'), Middlewares([CheckAuthMiddleware::class, ApiLockMiddleware::class])]
    public function updatePersonal(StaffRequest $request, StaffService $service): void
    {
        $service->updatePersonal($request->validated());
    }

    // 订单列表
    #[GetMapping('staff/orders'), Middlewares([CheckAuthMiddleware::class])]
    public function orderIndex(StaffService $service)
    {
        return $service->orderIndex();
    }

    /**
     * 订单详情
     * @param mixed $id
     * @param StaffService $service
     * @return Order
     */
    #[GetMapping('staff/orders/{id}'), Middlewares([CheckAuthMiddleware::class])]
    public function orderShow(mixed $id, StaffService $service): Order
    {
        return $service->orderShow($id);
    }

    /**
     * 确认送达
     * @param mixed $id
     * @param StaffService $service
     * @return void
     */
    #[PutMapping('staff/orders/{id}/delivery'), Middlewares([CheckAuthMiddleware::class, ApiLockMiddleware::class])]
    public function updateOrderDelivery(mixed $id, StaffService $service): void
    {
        $service->updateOrderDelivery($id);
    }
}
